﻿<UserControl x:Class="Kokomo.PeInspector.Reflection.SourceDocumentView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 xmlns:svc="clr-namespace:Kokomo.Environment.Services;assembly=Kokomo.Environment"
             mc:Ignorable="d" 
			 xmlns:kui="xaml://kokomo/ui"
             d:DesignHeight="300" d:DesignWidth="300">
	<UserControl.Resources>
		<BooleanToVisibilityConverter x:Key="boolVisibilityConverter"/>
	</UserControl.Resources>
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
		</Grid.RowDefinitions>

		<ToolBarTray>
			<ToolBarTray.Resources>
				<Style TargetType="{x:Type Image}">
					<Setter Property="Stretch" Value="Uniform"/>
					<Setter Property="StretchDirection" Value="Both"/>
					<Setter Property="Width" Value="16"/>
					<Setter Property="Height" Value="16"/>
				</Style>
			</ToolBarTray.Resources>
			<ToolBar>
				<Button Command="{Binding SaveDocumentCommand}" VerticalAlignment="Center">
					<StackPanel Orientation="Horizontal">
						<Image Source="{svc:Image SaveDocument}"/>
						<TextBlock Text="Save"/>
					</StackPanel>
				</Button>
				<Separator/>
				<TextBlock Text="Font:" VerticalAlignment="Center" Margin="2"/>
				<ComboBox
					VerticalAlignment="Center"
					SelectedItem="{Binding FontFamily}"
					ItemsSource="{Binding FontFamilyList}"
					VirtualizingStackPanel.IsVirtualizing="True"
					>
					<ComboBox.ItemTemplate>
						<DataTemplate>
							<TextBlock FontFamily="{Binding}" Text="{Binding Source}"/>
						</DataTemplate>
					</ComboBox.ItemTemplate>
				</ComboBox>
				<TextBlock Text="Font size:" Margin="2" VerticalAlignment="Center"/>
				<TextBox Text="{Binding FontSize}" VerticalAlignment="Center"/>
				<ToggleButton
					Content="Options"
					IsChecked="{Binding IsOptionsPaneVisible}"
					VerticalAlignment="Center"
					/>
			</ToolBar>
		</ToolBarTray>
		<Grid Grid.Row="1">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="*"/>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>

				<FlowDocumentReader
					ViewingMode="Scroll"
					Document="{Binding Document}"
					>
					<FlowDocumentReader.Resources>
						<Style TargetType="Hyperlink">
							<Setter Property="TextDecorations">
								<Setter.Value>
									<TextDecorationCollection>
										<TextDecoration>
											<TextDecoration.Pen>
												<Pen Thickness="1" Brush="Blue" DashStyle="{x:Static Member=DashStyles.Dash}"/>
											</TextDecoration.Pen>
										</TextDecoration>
									</TextDecorationCollection>
								</Setter.Value>
							</Setter>
						</Style>
					</FlowDocumentReader.Resources>
				</FlowDocumentReader>

				<ProgressBar
					IsIndeterminate="True"
					VerticalAlignment="Center"
					Height="20"
					Minimum="0"
					Maximum="100"
					Width="200"
					HorizontalAlignment="Center"
					>
					<ProgressBar.Style>
						<Style TargetType="{x:Type ProgressBar}">
							<Style.Triggers>
								<DataTrigger Binding="{Binding IsLoading}" Value="False">
									<Setter Property="Visibility" Value="Hidden"/>
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</ProgressBar.Style>
				</ProgressBar>

				<Border
					Grid.Column="1"
					Margin="2"
					Visibility="{Binding IsOptionsPaneVisible, Converter={StaticResource boolVisibilityConverter}}"
					>
					<ScrollViewer
						VerticalScrollBarVisibility="Auto"
						>
						<StackPanel>
							<Expander Header="Colors" IsExpanded="True">
								<ItemsControl
									ItemsSource="{Binding CodeTextFormatItems}"
									Grid.IsSharedSizeScope="True"
									>
									<ItemsControl.ItemTemplate>
										<DataTemplate>
											<Grid>
												<Grid.ColumnDefinitions>
													<ColumnDefinition Width="Auto" SharedSizeGroup="Label"/>
													<ColumnDefinition Width="6"/>
													<ColumnDefinition Width="Auto"/>
												</Grid.ColumnDefinitions>

												<TextBlock Text="{Binding Label}"/>
												<kui:ColorPicker Grid.Column="2" Margin="2" Color="{Binding Color}"/>
											</Grid>
										</DataTemplate>
									</ItemsControl.ItemTemplate>
								</ItemsControl>
							</Expander>

							<Button
								Content="Rebuild Document"
								Command="{Binding RebuildCommand}"
								HorizontalAlignment="Center"
								Padding="3"
								/>
						</StackPanel>
					</ScrollViewer>
				</Border>
			</Grid>
		</Grid>
	</Grid>
</UserControl>
